package org.gridgain.internal.h2.vector;

public class MyRight {
    private MyPage root;
    private Object key;
    private MyPage p;
    private int index;

    public MyPage getRoot() {
        return root;
    }

    public Object getKey() {
        return key;
    }

    public MyPage getP() {
        return p;
    }

    public int getIndex() {
        return index;
    }

    public MyRight(MyPage root, Object key, MyPage p, int index)
    {
        this.root = root;
        this.key = key;
        this.p = p;
        this.index = index;
    }

    public int getRight()
    {
        if (this.p.isLeaf() && this.index >= 0 && this.index < this.p.keys.length)
        {
            //Object obj = this.p.keys[this.index];
            int rs = this.index;
            this.index++;
            return rs;
        }
        else if (this.index >= this.p.keys.length)
        {
            MyPage page = MyUtil.rightPage(this.root, this.key);
            if (page != null)
            {
                this.p = page;
                this.index = 0;
                this.key = page.keys[this.index];

                if (this.p.isLeaf() && this.index >= 0 && this.index < this.p.keys.length)
                {
                    //Object obj = this.p.keys[this.index];
                    int rs = this.index;
                    this.index++;
                    return rs;
                }
            }
        }
        return -1;
    }

//    public Object getRight()
//    {
//        if (this.p.isLeaf() && this.index >= 0 && this.index < this.p.keys.length)
//        {
//            Object obj = this.p.keys[this.index];
//            this.index++;
//            return obj;
//        }
//        else if (this.index >= this.p.keys.length)
//        {
//            MyPage page = MyUtil.rightPage(this.root, this.key);
//            if (page != null)
//            {
//                this.p = page;
//                this.index = 0;
//                this.key = page.keys[this.index];
//
//                if (this.p.isLeaf() && this.index >= 0 && this.index < this.p.keys.length)
//                {
//                    Object obj = this.p.keys[this.index];
//                    this.index++;
//                    return obj;
//                }
//            }
//        }
//        return null;
//    }
}
